package com.gnerv.rabbitmq.agent.command;

import com.gnerv.rabbitmq.agent.model.entity.Node;
import com.gnerv.rabbitmq.agent.tools.ExecTools;
import com.google.common.collect.Lists;

import java.util.Arrays;
import java.util.List;

/**
 * @author Gnerv LiGen
 */
public class ParameterCommand extends AbstractRabbitmqctlCommand {

    public ParameterCommand(Node node){
        super();
        setNode(node);
    }

    public static ParameterCommand build(Node node){
        return new ParameterCommand(node);
    }

    public ExecTools.ExecResult clearGlobalParameter(String... name) {
        List<String> listExchanges = Lists.newArrayList();
        listExchanges.add("clear_global_parameter");
        listExchanges.add(Arrays.toString(name));
        return run(listExchanges);
    }

    public ExecTools.ExecResult clearParameter(String vhost, String... name) {
        List<String> listExchanges = Lists.newArrayList();
        listExchanges.add("clear_parameter");
        listExchanges.add("-p");
        listExchanges.add(vhost);
        listExchanges.add(Arrays.toString(name));
        return run(listExchanges);
    }

    public ExecTools.ExecResult listGlobalParameters() {
        List<String> listExchanges = Lists.newArrayList();
        listExchanges.add("list_global_parameters");
        return run(listExchanges);
    }

    public ExecTools.ExecResult listParameters() {
        List<String> listExchanges = Lists.newArrayList();
        listExchanges.add("list_parameters");
        return run(listExchanges);
    }

    public ExecTools.ExecResult setGlobalParameter(String name, String value) {
        List<String> listExchanges = Lists.newArrayList();
        listExchanges.add("set_global_parameter");
        listExchanges.add(name);
        listExchanges.add(value);
        return run(listExchanges);
    }

    public ExecTools.ExecResult setParameter(String vhost, String name, String value) {
        List<String> listExchanges = Lists.newArrayList();
        listExchanges.add("set_parameter");
        listExchanges.add("-p");
        listExchanges.add(vhost);
        listExchanges.add(name);
        listExchanges.add(value);
        return run(listExchanges);
    }

}
